package 晚间作业0316.Doc11_课后习题;

import java.util.Random;

/**
 * 小明去饭店吃饭，身上带了22块钱，随机产生[15, 30]范围的饭钱，如果小明的钱不够支付饭钱，
 * 抛出一个NotEnoughMoneyException的运行时异常。
 */
public class Doc11_04 {

    public static void main(String[] args) throws NotEnoughMoneyException {
        Person xiaoming = new Person("小明", 22);
        double amount = new Random().nextDouble() * 15 + 15;
        System.out.println("支付：" + amount + "元");
        xiaoming.pay(amount);
    }

    private static class Person {
        private String name;
        private double rmb;

        public Person(String name, double rmb) {
            this.name = name;
            this.rmb = rmb;
        }

        public void pay(double amount) throws NotEnoughMoneyException {
            if (amount > rmb) {
                throw new NotEnoughMoneyException();
            }
            System.out.println("支付成功");
        }
    }

    public static class NotEnoughMoneyException extends Exception {
        public NotEnoughMoneyException() {
            super();
        }
    }
}
